﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Progetto.Beans;
using Progetto.Model_Stuff;
using Progetto.Controller_Stuff;

namespace Progetto
{
    public partial class FPForm : Form
    {
        private DateTime _selectedDay;
        private Model _model = new Model();
        private Controller _controller;

        public FPForm()
        {
            InitializeComponent();
            _selectedDay = _monthCalendar.SelectionStart;
            _controller = new Controller(_model);

            #region Monday
            if (_selectedDay.DayOfWeek == DayOfWeek.Monday)
            {
                foreach (Event e in _controller.getPublicEvents())
                {
                    if (e.StartDate == _selectedDay)
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.MondayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(1))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.TuesdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(2))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.WednesdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(3))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.ThursdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(4))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.FridayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(5))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.SaturdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(6))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.SundayCalendar.Controls.Add(ep);
                    }

                }

                foreach (MyCalendar calendar in _controller.getMyCalendars()) 
                {
                    Calendar calendarGUI = new Calendar();
                    calendarGUI.Dock = DockStyle.Fill;
                    foreach (Event e in _controller.getEventsFromCalendar(calendar))
                    {
                        if (e.StartDate == _selectedDay)
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.MondayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(1))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.TuesdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(2))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.WednesdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(3))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.ThursdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(4))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.FridayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(5))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.SaturdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(6))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.SundayCalendar.Controls.Add(ep);
                        }
                    }
                    TabPage calTabPage = new TabPage(calendar.Name);
                    calTabPage.BackColor = Color.FromName(calendar.Color);
                    calTabPage.Controls.Add(calendarGUI);
                    _myCalendarsTabs.TabPages.Add(calTabPage);                   
                }

            }
            #endregion

            #region Tuesday
            if (_selectedDay.DayOfWeek == DayOfWeek.Tuesday)
            {
                foreach (Event e in _controller.getPublicEvents())
                {
                    if (e.StartDate == _selectedDay.AddDays(-1))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.MondayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay)
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.TuesdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(1))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.WednesdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(2))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.ThursdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(3))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.FridayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(4))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.SaturdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(5))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.SundayCalendar.Controls.Add(ep);
                    }
                }

                foreach (MyCalendar calendar in _controller.getMyCalendars())
                {
                    Calendar calendarGUI = new Calendar();
                    calendarGUI.Dock = DockStyle.Fill;
                    foreach (Event e in _controller.getEventsFromCalendar(calendar))
                    {
                        if (e.StartDate == _selectedDay.AddDays(-1))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.MondayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay)
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.TuesdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(1))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.WednesdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(2))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.ThursdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(3))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.FridayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(4))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.SaturdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(5))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.SundayCalendar.Controls.Add(ep);
                        }
                    }
                    TabPage calTabPage = new TabPage(calendar.Name);
                    calTabPage.BackColor = Color.FromName(calendar.Color);
                    calTabPage.Controls.Add(calendarGUI);
                    _myCalendarsTabs.TabPages.Add(calTabPage);
                }

            }
            #endregion

            #region Wednesday
            if (_selectedDay.DayOfWeek == DayOfWeek.Wednesday)
            {
                foreach (Event e in _controller.getPublicEvents())
                {
                    if (e.StartDate == _selectedDay.AddDays(-2))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.MondayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(-1))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.TuesdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay)
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.WednesdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(1))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.ThursdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(2))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.FridayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(3))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.SaturdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(4))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.SundayCalendar.Controls.Add(ep);
                    }
                }


                foreach (MyCalendar calendar in _controller.getMyCalendars())
                {
                    Calendar calendarGUI = new Calendar();
                    calendarGUI.Dock = DockStyle.Fill;
                    foreach (Event e in _controller.getEventsFromCalendar(calendar))
                    {
                        if (e.StartDate == _selectedDay.AddDays(-2))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.MondayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(-1))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.TuesdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay)
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.WednesdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(1))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.ThursdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(2))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.FridayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(3))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.SaturdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(4))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.SundayCalendar.Controls.Add(ep);
                        }
                    }
                    TabPage calTabPage = new TabPage(calendar.Name);
                    calTabPage.BackColor = Color.FromName(calendar.Color);
                    calTabPage.Controls.Add(calendarGUI);
                    _myCalendarsTabs.TabPages.Add(calTabPage);
                }
            }
            #endregion

            #region Thursday
            if (_selectedDay.DayOfWeek == DayOfWeek.Thursday)
            {
                foreach (Event e in _controller.getPublicEvents())
                {
                    if (e.StartDate == _selectedDay.AddDays(-3))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.MondayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(-2))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.TuesdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(-1))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.WednesdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay)
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.ThursdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(1))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.FridayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(2))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.SaturdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(3))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.SundayCalendar.Controls.Add(ep);
                    }
                }

                foreach (MyCalendar calendar in _controller.getMyCalendars())
                {
                    Calendar calendarGUI = new Calendar();
                    calendarGUI.Dock = DockStyle.Fill;
                    foreach (Event e in _controller.getEventsFromCalendar(calendar))
                    {
                        if (e.StartDate == _selectedDay.AddDays(-3))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.MondayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(-2))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.TuesdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(-1))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.WednesdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay)
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.ThursdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(1))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.FridayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(2))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.SaturdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(3))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.SundayCalendar.Controls.Add(ep);
                        }
                    }
                    TabPage calTabPage = new TabPage(calendar.Name);
                    calTabPage.BackColor = Color.FromName(calendar.Color);
                    calTabPage.Controls.Add(calendarGUI);
                    _myCalendarsTabs.TabPages.Add(calTabPage);
                }
            }
            #endregion

            #region Friday
            if (_selectedDay.DayOfWeek == DayOfWeek.Friday)
            {
                foreach (Event e in _controller.getPublicEvents())
                {
                    if (e.StartDate == _selectedDay.AddDays(-4))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.MondayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(-3))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.TuesdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(-2))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.WednesdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(-1))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.ThursdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay)
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.FridayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(1))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.SaturdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(2))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.SundayCalendar.Controls.Add(ep);
                    }
                }

                foreach (MyCalendar calendar in _controller.getMyCalendars())
                {
                    Calendar calendarGUI = new Calendar();
                    calendarGUI.Dock = DockStyle.Fill;
                    foreach (Event e in _controller.getEventsFromCalendar(calendar))
                    {
                        if (e.StartDate == _selectedDay.AddDays(-4))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.MondayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(-3))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.TuesdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(-2))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.WednesdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(-1))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.ThursdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay)
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.FridayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(1))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.SaturdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(2))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.SundayCalendar.Controls.Add(ep);
                        }
                    }
                    TabPage calTabPage = new TabPage(calendar.Name);
                    calTabPage.BackColor = Color.FromName(calendar.Color);
                    calTabPage.Controls.Add(calendarGUI);
                    _myCalendarsTabs.TabPages.Add(calTabPage);
                }
            }
            #endregion

            #region Saturday
            if (_selectedDay.DayOfWeek == DayOfWeek.Saturday)
            {
                foreach (Event e in _controller.getPublicEvents())
                {
                    if (e.StartDate == _selectedDay.AddDays(-5))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.MondayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(-4))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.TuesdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(-3))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.WednesdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(-2))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.ThursdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(-1))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.FridayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay)
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.SaturdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(1))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.SundayCalendar.Controls.Add(ep);
                    }
                }

                foreach (MyCalendar calendar in _controller.getMyCalendars())
                {
                    Calendar calendarGUI = new Calendar();
                    calendarGUI.Dock = DockStyle.Fill;
                    foreach (Event e in _controller.getEventsFromCalendar(calendar))
                    {
                        if (e.StartDate == _selectedDay.AddDays(-5))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.MondayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(-4))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.TuesdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(-3))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.WednesdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(-2))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.ThursdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(-1))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.FridayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay)
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.SaturdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(1))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.SundayCalendar.Controls.Add(ep);
                        }
                    }
                    TabPage calTabPage = new TabPage(calendar.Name);
                    calTabPage.BackColor = Color.FromName(calendar.Color);
                    calTabPage.Controls.Add(calendarGUI);
                    _myCalendarsTabs.TabPages.Add(calTabPage);
                }
            }
            #endregion

            #region Sunday
            if (_selectedDay.DayOfWeek == DayOfWeek.Sunday)
            {
                foreach (Event e in _controller.getPublicEvents())
                {
                    if (e.StartDate == _selectedDay.AddDays(-6))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.MondayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(-5))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.TuesdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(-4))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.WednesdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(-3))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.ThursdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(-2))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.FridayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay.AddDays(-1))
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.SaturdayCalendar.Controls.Add(ep);
                    }

                    if (e.StartDate == _selectedDay)
                    {
                        EventPreview ep = new EventPreview(e);
                        _generalCalendar.SundayCalendar.Controls.Add(ep);
                    }
                }

                foreach (MyCalendar calendar in _controller.getMyCalendars())
                {
                    Calendar calendarGUI = new Calendar();
                    calendarGUI.Dock = DockStyle.Fill;
                    foreach (Event e in _controller.getEventsFromCalendar(calendar))
                    {
                        if (e.StartDate == _selectedDay.AddDays(-6))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.MondayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(-5))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.TuesdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(-4))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.WednesdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(-3))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.ThursdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(-2))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.FridayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay.AddDays(-1))
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.SaturdayCalendar.Controls.Add(ep);
                        }

                        if (e.StartDate == _selectedDay)
                        {
                            EventPreview ep = new EventPreview(e);
                            calendarGUI.SundayCalendar.Controls.Add(ep);
                        }
                    }
                    TabPage calTabPage = new TabPage(calendar.Name);
                    calTabPage.BackColor = Color.FromName(calendar.Color);
                    calTabPage.Controls.Add(calendarGUI);
                    _myCalendarsTabs.TabPages.Add(calTabPage);
                }
            }
            #endregion

        }



    }
}
            

          